package com.beiding.editanalyzeframe;

/**
 * 最左相同
 * @author 丁常磊
 * @date 2022/9/9 14:21
 */

public class MaxLeftSameEditPossibility implements EditPossibility {

    /**
     * 编辑可能性
     *
     * @param a
     * @param b
     * @return
     */
    @Override
    public double editPossibility(String a, String b) {

        //最左相似
        int size = a.length() < b.length() ? a.length() : b.length();
        int i = 0;
        for (; i < size; i++) {
            if (a.charAt(i) != b.charAt(i)) {
                break;
            }
        }

        return i * 2.0 / (a.length() + b.length());
    }

}
